#include "StdAfx.h"
#include "DD_SvrNetSDK.h"

#include "DDSvrNetMan.h"

DWORD __stdcall DD_SvrNet_GetSdkVersion()
{
	return 0;
}

DDERR_CODE __stdcall DD_SvrNet_Init(HANDLE &hSvrNet)
{
	DDSvrNetMan *pSvrNet = new DDSvrNetMan();
	if( NULL == pSvrNet )
	{
		return DD_ERR_FAILURE;
	}

    hSvrNet = (HANDLE)pSvrNet;

	return DD_ERR_SUCCESS;
}

DDERR_CODE __stdcall DD_SvrNet_Cleanup(HANDLE hSvrNet)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	delete pSvrNet;
	pSvrNet = NULL;

	return DD_ERR_SUCCESS;
}

DDERR_CODE __stdcall DD_SvrNet_SetConnectTime(HANDLE hSvrNet,DWORD dwWaitTime, DWORD dwTryTimes)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->SetConnectTime(dwWaitTime,dwTryTimes);
}

DDERR_CODE __stdcall DD_SvrNet_GetIPList(HANDLE hSvrNet,char **ppszIPList[DD_IPADDR_LEN],unsigned int &nCount)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->GetIPList(ppszIPList,nCount);
}

DDERR_CODE __stdcall DD_SvrNet_SetListen(HANDLE hSvrNet,char *pszIP, unsigned short nListenPort)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->SetListen(pszIP,nListenPort);
}

DDERR_CODE	__stdcall DD_SvrNet_CheckFlag(HANDLE hSvrNet,DWORD *pdwFlag)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->CheckFlag(pdwFlag);
}


DDERR_CODE __stdcall DD_SvrNet_RegCheckUserCallBack(HANDLE hSvrNet,SvrNetCheckUserCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegCheckUserCallBack(funCallBack,pContext);
}

DDERR_CODE __stdcall DD_SvrNet_RegCheckUserRightCallBack(HANDLE hSvrNet,SvrNetCheckUserRightCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegCheckUserRightCallBack(funCallBack,pContext);
}



DDERR_CODE __stdcall DD_SvrNet_RegSetConfigCallBack(HANDLE hSvrNet,SvrNetSetConfigCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegSetConfigCallBack(funCallBack,pContext);
}

DDERR_CODE __stdcall DD_SvrNet_RegGetConfigCallBack(HANDLE hSvrNet,SvrNetGetConfigCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegGetConfigCallBack(funCallBack,pContext);
}


DDERR_CODE __stdcall DD_SvrNet_RegStartSearchCallBack(HANDLE hSvrNet,SvrNetStartSearchCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegStartSearchCallBack(funCallBack,pContext);
}

DDERR_CODE __stdcall DD_SvrNet_RegStopSearchCallBack(HANDLE hSvrNet,SvrNetStopSearchCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegStopSearchCallBack(funCallBack,pContext);
}

DDERR_CODE __stdcall DD_SvrNet_RegfwOpenCallBack(HANDLE hSvrNet,SvrNetfwOpenCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegfwOpenCallBack(funCallBack,pContext);
}
DDERR_CODE __stdcall DD_SvrNet_RegfWriteCallBack(HANDLE hSvrNet,SvrNetfWriteCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegfWriteCallBack(funCallBack,pContext);
}
DDERR_CODE __stdcall DD_SvrNet_RegfwCloseCallBack(HANDLE hSvrNet,SvrNetfwCloseCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegfwCloseCallBack(funCallBack,pContext);
}
DDERR_CODE __stdcall DD_SvrNet_RegfrOpenCallBack(HANDLE hSvrNet,SvrNetfrOpenCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegfrOpenCallBack(funCallBack,pContext);
}
DDERR_CODE __stdcall DD_SvrNet_RegfReadCallBack(HANDLE hSvrNet,SvrNetfReadCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegfReadCallBack(funCallBack,pContext);
}
DDERR_CODE __stdcall DD_SvrNet_RegfrCloseCallBack(HANDLE hSvrNet,SvrNetfrCloseCBFun funCallBack,void *pContext)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->RegfrCloseCallBack(funCallBack,pContext);
}


DDERR_CODE __stdcall DD_SvrNet_Start(HANDLE hSvrNet)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->SvrStart();
}

DDERR_CODE __stdcall DD_SvrNet_Stop(HANDLE hSvrNet)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->SvrStop();
}


DDERR_CODE __stdcall DD_SvrNet_Found_Notify(HANDLE hSvrNet,HANDLE hHandle,void *pBuffer,DWORD dwBufferSize)
{
	DDSvrNetMan *pSvrNet = (DDSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return DD_ERR_PARAMETER;
	}

	return (DDERR_CODE)pSvrNet->m_xLoginMan.SearchFoundNotify(hHandle,pBuffer,dwBufferSize);
}

